import org.antlr.runtime.ANTLRFileStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.tree.CommonTreeNodeStream;
import org.antlr.runtime.tree.Tree;

public class Main {
   public static void main(String args[]) throws Exception {

	   
	  try {
	      XHTML2CSVLexer lex = new XHTML2CSVLexer(new ANTLRFileStream(args[0]));	// create lexer to read the file specified from command line (i.e., first argument, e.g., java Main test1.xhtml)
	      CommonTokenStream tokens = new CommonTokenStream(lex);					// transform it into a token stream
	      XHTML2CSVParser parser = new XHTML2CSVParser(tokens);						// create the parser that reads from the token stream
	
	      Tree t = (Tree) parser.balise_table().tree;								// (try to) parse a given rule specified in the parser file, e.g., my_main_rule
	
	    	   
	       CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);				// transform it into a common data structure readable by the tree pattern
	       nodes.setTokenStream(tokens);											// declare which token to use (i.e., labels of the nodes defined in the parser, mainly anonymous tokens)
	       XHTML2CSVTree tparser = new XHTML2CSVTree(nodes);						// instantiate the tree pattern
	       System.out.println(tparser.tableau());													// apply patterns
	   } catch (Exception e) {
		   e.printStackTrace();
	   }
   }
}
